using System;
using System.Collections;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
namespace BMC.ARSystem
{
	[ARStructTypeInfo(Name = "ARCurrencyStruct", NumberOfMembers = 4u), ClassInterface, Guid("eb61f2cd-85ba-4c4b-b0a2-e2791675c86c"), ProgId("BMC.ARSystem.CurrencyValue")]
	public class CurrencyValue
	{
		[ARStructMemTypeInfo(Name = "value", Offset = 0u)]
		private string _value;
		[ARStructMemTypeInfo(Name = "currencyCode", Offset = 1u)]
		private string _currencyCode;
		[ARStructMemTypeInfo(Name = "conversionDate", Offset = 2u)]
		private DateTime _conversionDate;
		[ARStructMemTypeInfo(Name = "funcList", Offset = 3u, IsList = true, MemberType = "object")]
		private ArrayList _funcList;
		public decimal Value
		{
			get
			{
				return Util.ToDecimal(this._value);
			}
			set
			{
				this._value = value.ToString();
			}
		}
		public string CurrencyCode
		{
			get
			{
				return this._currencyCode;
			}
			set
			{
				this._currencyCode = value;
			}
		}
		public DateTime ConversionDate
		{
			get
			{
				return this._conversionDate;
			}
			set
			{
				this._conversionDate = value;
			}
		}
		public ArrayList FunctionalCurrencies
		{
			get
			{
				return this._funcList;
			}
			set
			{
				this._funcList = value;
			}
		}
		public CurrencyValue()
		{
			this.ConversionDate = new DateTime(1970, 1, 1);
			this._funcList = new ArrayList();
		}
		public CurrencyValue(decimal val, string code)
		{
			this.ConversionDate = new DateTime(1970, 1, 1);
			this._funcList = new ArrayList();
			this.Value = val;
			this.CurrencyCode = code;
		}
		internal CurrencyValue(object[] rawData, Server server)
		{
			int[] indexSpec = new int[1];
			this.Value = Util.ToDecimal(Util.GetAt(rawData, indexSpec));
			this.CurrencyCode = (string)Util.GetAt(rawData, new int[]
			{
				1
			});
			this.ConversionDate = Util.GetDateTime(Convert.ToUInt32(Util.GetAt(rawData, new int[]
			{
				2
			})));
			this.FunctionalCurrencies = new ArrayList((object[])Util.GetAt(rawData, new int[]
			{
				3
			}));
		}
		internal static CurrencyValue createInstance(object[] rawData, Server server)
		{
			return new CurrencyValue(rawData, server);
		}
		public void SetFunctionalValue(string code, decimal val)
		{
			this._funcList.Add(new object[]
			{
				val,
				code
			});
		}
		public override string ToString()
		{
			return string.Format("{0} {1}", this.Value, this.CurrencyCode);
		}
		internal static CurrencyValue Decode(string val)
		{
			Regex regex = new Regex("^([^\\004]+)\\004([^\\004]+)(.*)");
			CurrencyValue currencyValue = new CurrencyValue();
			if (regex.IsMatch(val))
			{
				currencyValue.Value = Util.ToDecimal(regex.Replace(val, "$1"));
				currencyValue.CurrencyCode = regex.Replace(val, "$2");
				string text = regex.Replace(val, "$3");
				regex = new Regex("\\004([0-9]+)\\004(.*)");
				if (regex.IsMatch(text))
				{
					string text2 = regex.Replace(text, "$1");
					currencyValue.ConversionDate = Util.GetDateTime(Convert.ToUInt32(text2));
					text = regex.Replace(text, "$2");
					regex = new Regex("[0-9]+(\\004.*)");
					text = regex.Replace(text, "$1");
					regex = new Regex("\\004(-?[0-9\\.]*)\\004([A-Z][A-Z][A-Z])(.*)");
					while (regex.IsMatch(text))
					{
						string text3 = regex.Replace(text, "$1");
						string code = regex.Replace(text, "$2");
						text = regex.Replace(text, "$3");
						if (text3.get_Length() > 0)
						{
							currencyValue.SetFunctionalValue(code, Util.ToDecimal(text3));
						}
					}
				}
			}
			return currencyValue;
		}
		internal string Encode()
		{
			string text = "";
			text += this.Value;
			text += '\u0004';
			text += this.CurrencyCode;
			text += '\u0004';
			text += Util.GetARTimestamp(this.ConversionDate).ToString();
			text += '\u0004';
			text += this.FunctionalCurrencies.get_Count();
			text += '\u0004';
			IEnumerator enumerator = this.FunctionalCurrencies.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object[] array = (object[])enumerator.get_Current();
					text += array[0];
					text += '\u0004';
					text += array[1];
					text += '\u0004';
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			return text;
		}
	}
}
